package com.eastfair.home.service.impl;

import com.alibaba.fastjson.JSONObject;
import com.eastfair.core.base.R;
import com.eastfair.core.exception.BizException;
import com.eastfair.home.service.SpecsService;
import com.eastfair.venuebooking.api.ServiceCategoryFeign;
import com.eastfair.venuebooking.api.ServiceSpecsFeign;
import com.eastfair.venueservice.dto.ServiceSpecsDTO;
import com.eastfair.venueservice.vo.ServiceSpecsVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @Author suolong
 * @Date 2022/8/9 9:44
 */
/**
 * <p>
 * 业务实现类
 * 服务分类规格
 * </p>
 *
 * @author lye
 * @date 2022-08-09
 */
@Slf4j
@Service
public class SpecsServiceImpl implements SpecsService {

    @Autowired
    private ServiceSpecsFeign serviceSpecsFeign;

    /**
     * 根据服务分类id查规格
     * @param categoryId
     * @return
     */
    @Override
    public List<ServiceSpecsVO> getSpecsListByCategoryId(Long categoryId) {
        log.info("SpecsServiceImpl +++++ getSpecsListByCategoryId - 根据服务分类id查规格 params={}", categoryId);
        R<List<ServiceSpecsVO>> r = serviceSpecsFeign.getServiceSpecsListByCategoryId(categoryId);
        if(!r.getIsSuccess()){
            throw BizException.wrap(r.getCode(),r.getMsg());
        }
        return r.getData();
    }

    /**
     * 保存服务规格
     * @param serviceSpecsDTO
     * @return
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public Boolean saveSpecsInfo(ServiceSpecsDTO serviceSpecsDTO) {
        log.info("SpecsServiceImpl +++++ saveSpecsInfo -保存服务规格 params={}", JSONObject.toJSON(serviceSpecsDTO));
        R<Boolean> r = serviceSpecsFeign.saveServiceSpecsInfo(serviceSpecsDTO);
        if(!r.getIsSuccess()){
            throw BizException.wrap(r.getCode(),r.getMsg());
        }
        return r.getData();
    }

    /**
     * 删除服务规格
     * @param id
     * @return
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public Boolean delSpecsById(Long id) {
        log.info("SpecsServiceImpl +++++ delSpecsById -删除服务规格 params={}", id);
        R<Boolean> r = serviceSpecsFeign.delServiceSpecsById(id);
        if(!r.getIsSuccess()){
            throw BizException.wrap(r.getCode(),r.getMsg());
        }
        return r.getData();
    }


}
